package com.collection;

import java.util.ArrayList;

public class CollectionDemo2 {
    public static void main(String[] args) {
        ArrayList c = new ArrayList();
        c.add(new Point(1, 2));
        c.add(new Point(3, 4));
        c.add(new Point(5, 6));
        c.add(new Point(7, 8));
        c.add(new Point(1, 2));
        /**
         * 集合重写了toString方法，返回的字符串格式:
         * [com.collection.Point@3e2, com.collection.Point@422, com.collection.Point@462, com.collection.Point@4a2]
         */
        System.out.println(c);


        /**
         * contains(Object o)
         * 返回 true如果这个集合包含指定的元素。
         * 这里必须重写equals()方法
         */
        Point point = new Point(1, 2);
        boolean contains = c.contains(point);
        System.out.println("判断集合包含指定的元素 = " + contains);

        /**
         * remove(Object o)
         * 删除指定元素的单个实例从这个集合,如果它存在(可选操作)。
         * remove只删除一个元素，即使重复也是只删除一个
         */
        boolean remove = c.remove(point);
        System.out.println("remove = " + remove);
        System.out.println(c);//[Point{x=3, y=4}, Point{x=5, y=6}, Point{x=7, y=8}, Point{x=1, y=2}]
    }
}
